package br.com.marcelo.reservasis.domain.model;

import br.com.aroeirasoftware.gwtcomponents.domain.models.ASBaseEntity;
import java.io.Serializable;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.Cascade;

/**
 *
 * @author Kirmaier
 */
@Entity
@Table(name = "Apartamento")
public class Apartamento extends ASBaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "Id_Apart")
    private Integer idapart;
    @Column(name = "Num_Apart")
    private Integer numApart;
    @Column(name = "Descricao_Apart")
    private String descricaoApart;
    @Column(name = "Num_Quartos_Apart")
    private Integer numQuartosApart;
    @Cascade({
        org.hibernate.annotations.CascadeType.SAVE_UPDATE
    })
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "Id_tipo", insertable = true, updatable = true, nullable = false)
    private TipoApartamento tipoApartamento;
    @OneToMany(mappedBy = "apartamento")
    private Set<ReservaEstadia> reservasEstadias;

    public Apartamento() {
    }

    public Integer getIdapart() {
        return idapart;
    }

    public void setIdapart(Integer idapart) {
        this.idapart = idapart;
    }

    public Apartamento(Integer numApart) {
        this.numApart = numApart;
    }

    public Integer getNumApart() {
        return numApart;
    }

    public void setNumApart(Integer numApart) {
        this.numApart = numApart;
    }

    public String getDescricaoApart() {
        return descricaoApart;
    }

    public void setDescricaoApart(String descricaoApart) {
        this.descricaoApart = descricaoApart;
    }

    public TipoApartamento getTipoApartamento() {
        return tipoApartamento;
    }

    public void setTipoApartamento(TipoApartamento tipoApartamento) {
        this.tipoApartamento = tipoApartamento;
        tipoApartamento.getApartamentos().add(this);
    }

    public Integer getNumQuartosApart() {
        return numQuartosApart;
    }

    public void setNumQuartosApart(Integer numQuartosApart) {
        this.numQuartosApart = numQuartosApart;
    }

    public Set<ReservaEstadia> getReservasEstadias() {
        return reservasEstadias;
    }

    public void setReservasEstadias(Set<ReservaEstadia> reservasEstadias) {
        this.reservasEstadias = reservasEstadias;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (numApart != null ? numApart.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Apartamento)) {
            return false;
        }
        Apartamento other = (Apartamento) object;
        if ((this.numApart == null && other.numApart != null) || (this.numApart != null && !this.numApart.equals(other.numApart))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.reservasis.Apartamento[numApart=" + numApart + "]";
    }
}